﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProjetoFinal.Resources.ReedSolomon
{
    static class RSUtils
    {
        
        public static void encode(int[] toEncode, int ecBytes, int typeOfEncoding) 
        {
            ReedSolomonEncoder encoder = new ReedSolomonEncoder(GenericGF.AZTEC_PARAM);

            switch (typeOfEncoding)
            {
                case 16:
                    encoder = new ReedSolomonEncoder(GenericGF.AZTEC_PARAM);
                    break;
                case 256:
                    encoder = new ReedSolomonEncoder(GenericGF.DATA_MATRIX_FIELD_256);
                    break;
                case 1024:
                    encoder = new ReedSolomonEncoder(GenericGF.AZTEC_DATA_10);
                    break;
                case 4096:
                    encoder = new ReedSolomonEncoder(GenericGF.AZTEC_DATA_12);
                    break;
            }

            encoder.encode(toEncode, ecBytes);
        }

        public static bool decode(int[] received, int twoS, int typeOfEncoding)
        {

            ReedSolomonDecoder decoder = new ReedSolomonDecoder(GenericGF.AZTEC_PARAM);

            switch (typeOfEncoding)
            {
                case 16:
                    decoder = new ReedSolomonDecoder(GenericGF.AZTEC_PARAM);
                    break;
                case 256:
                    decoder = new ReedSolomonDecoder(GenericGF.DATA_MATRIX_FIELD_256);
                    break;
                case 1024:
                    decoder = new ReedSolomonDecoder(GenericGF.AZTEC_DATA_10);
                    break;
                case 4096:
                    decoder = new ReedSolomonDecoder(GenericGF.AZTEC_DATA_12);
                    break;
            }

            return decoder.decode(received, twoS);;
        }
    }
}
